import Vue from 'vue'
import Router from 'vue-router'

//测试文件上传服务器
import MyUpload from '@/components/upload'

//公共组件
import Editor from '@/components/Editor'
import Test from '@/components/Test'

//管理员界面
import Error from '@/pages/error'
import Success from '@/pages/success'
import Login from '@/pages/Login'
import Password from '@/pages/Password'
import Register from '@/pages/Register'
import HelloWorld from '@/pages/HelloWorld/HelloWorld'


//二级路由 HelloWorld.vue 中使用
import Manage from '@/pages/HelloWorld/Article/Manage'
import PersonInfo from '@/pages/HelloWorld/PersonInfo/PersonInfo'
import UserList from '@/pages/HelloWorld/UserManage/UserList'
// import CreateCode from '@/pages/HelloWorld/UserManage/CreateCode'
// import Review from '@/pages/HelloWorld/appReview/AppReview'
// import TeacherEditor from '@/pages/HelloWorld/TeacherEditor/TeacherEditor'
import MyCollect from '@/pages/HelloWorld/MyCollect/Collect'
import MyComment from '@/pages/HelloWorld/MyComment/Comment'
import MyHistory from '@/pages/HelloWorld/MyHistory/History'
import MyLike from '@/pages/HelloWorld/MyLike/Like'


//root用户界面
// import AcademyManage from '@/pages/Root/AcademyManage'
// import Root from '@/pages/Root/root'
// import AD from '@/pages/Root/AD/AD'
// import ADList from '@/pages/Root/AD/ADList'



Vue.use(Router)

const router =  new Router({
    routes: [{
            path: '/',
            name: 'Login',
            component: Login,
        },
        {
            path: '/register',
            name: 'Register',
            component: Register,
        },
        {
            path: '/upload',
            name: 'MyUpload',
            component: MyUpload,
        },
        {
            path: '/hello',
            name: 'HelloWorld',
            component: HelloWorld,
            children: [{
                    path: '/error',
                    name: 'Error',
                    component: Error,
                },
                {
                    path: '/success',
                    name: 'Success',
                    component: Success,
                },
                {
                    path: '/editor',
                    name: 'Editor',
                    component: Editor,
                },
                {
                    path: '/manage',
                    name: 'Manage',
                    component: Manage,
                },
                {
                    path: '/personinfo',
                    name: 'PersonInfo',
                    component: PersonInfo,
                },
                {
                    path: '/userlist',
                    name: 'UserList',
                    component: UserList,
                },
                {
                    path: '/password',
                    name: 'Password',
                    component: Password,
                },
                {
                    path: '/collect',
                    name: 'MyCollect',
                    component: MyCollect,
                },
                {
                    path: '/like',
                    name: 'MyLike',
                    component: MyLike,
                },
                {
                    path: '/comment',
                    name: 'MyComment',
                    component: MyComment,
                },
                {
                    path: '/history',
                    name: 'MyHistory',
                    component: MyHistory,
                },
                //废弃使用
                // {
                //     path: '/review',
                //     name: 'Review',
                //     component: Review,
                // },
                // {
                //     path: '/teacher/editor',
                //     name: 'TeacherEditor',
                //     component: TeacherEditor,
                // },
                // {
                //     path: '/createcode',
                //     name: 'CreateCode',
                //     component: CreateCode,
                // },
                
            ]
        },
        //下面是广告添加，不需要这个页面
        // {
        //     path: '/root',
        //     name: 'Root',
        //     component: Root,
        //     children:[
        //         {
        //             path: 'ad',
        //             name: 'AD',
        //             component: AD,
        //         },
        //         {
        //             path: 'adlist',
        //             name: 'ADList',
        //             component: ADList,
        //         },
        //         {
        //             path: 'academyManage',
        //             name: 'AcademyManage',
        //             component: AcademyManage,
        //         },
        //     ]
        // },
        // {
        //     path : '/test',
        //     name : '',
        //     component: Test,
        // }
    ]
})

// 全局路由守卫
// router.beforeEach((to, from, next) => {
//     // to: Route: 即将要进入的目标 路由对象
//     // from: Route: 当前导航正要离开的路由
//     // next: Function: 一定要调用该方法来 resolve 这个钩子。执行效果依赖 next 方法的调用参数。
//     let isLogin = this.$store.getters.getUser.isLogin;  // 是否登录
//     if(isLogin){

//     }else{

//     }

//     // 未登录状态；当路由到nextRoute指定页时，跳转至login
//     if (nextRoute.indexOf(to.name) >= 0) {  
//       if (!isLogin) {
//         console.log('what fuck');
//         router.push({ name: 'login' })
//       }
//     }
//     // 已登录状态；当路由到login时，跳转至home 
//     if (to.name === 'login') {
//       if (isLogin) {
//         router.push({ name: 'home' });
//       }
//     }
//     next();
//   });


export default router;